package de.bensoft.jrail.client.ui.trackplan.segments;

import java.util.ArrayList;
import java.util.List;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import de.bensoft.jrail.business.entity.Trackplan;
import de.bensoft.jrail.business.entity.TrackplanSegment;

public class BasicTrackSegment extends Pane {

	// GUI
	private ImageView imv;
	
	private Integer row, column;
	protected Double size;
	
	private TrackplanSegment segmentData;
	public TrackplanSegment getSegmentData() { return segmentData; }
	public void setSegmentData(TrackplanSegment segmentData) { this.segmentData = segmentData; }

	
	private List<SegmentDockings> dockings;
	
	public BasicTrackSegment() {	
		this.getStyleClass().add("tracksegment");	
		
		imv = new ImageView();
		this.getChildren().add(imv);
		
		dockings = new ArrayList<SegmentDockings>();
	}
	
	private void doSize() {
		imv.setFitHeight (size);
		imv.setFitWidth	 (size);
		this.setPrefSize (size, size);	
	}
	
	public void addDocking(SegmentDockings docking) {
		if(!dockings.contains(docking))
			dockings.add(docking);
	}
	
	
	private String iconURL;
	public String getIconURL() { return iconURL; }

	public void setIcon(String url) {
		iconURL = url;
		imv.setImage(new Image(url));
	}
	
	public void setGraphic(String icon) {
		imv.setImage(new Image(icon));
	}
	
	public void removeGraphic() {
		if(imv!=null)
		this.getChildren().remove(imv);
	}
	
	public TrackplanSegment generateData(Trackplan plan) {
		TrackplanSegment segment = new TrackplanSegment();
		segment.setRow(row);
		segment.setCol(column);
		segment.setType(this.getClass().getName());
		segment.setTrackplan(plan);
		
		setSegmentData(segment);
		return segment;
	}
	
	public void onClicked(MouseEvent event) {
		
	}

	public Integer getRow() {
		return row;
	}

	public void setRow(Integer row) {
		this.row = row;
	}

	public Integer getColumn() {
		return column;
	}

	public void setColumn(Integer column) {
		this.column = column;
	}

	public Double getSize() {
		return size;
	}

	public void setSize(Double size) {
		this.size = size;
		doSize();
	}
	
	
}
